$(function(){
	recieveState();
    setInterval('dianzan();', 30000);  //每隔30秒循环执行过程函数！     
});
function dianzan() {  
	var actId = $("#actId").val();
	var url = basePath+"/commonluckymoney/pageView.do";
	$.ajax({
		url : url,
		type : 'post',
		dataType : 'json',
		data : {
			actId : actId
		},
		success : function(data, status) {
			if (data.success) {
				$('span[name="dianzan"]').html(data.obj);
			} else {
				
			}
		}
	});
}  
function recieveState() {  
	var actId = $("#actId").val();
	var openid = $("#openid").val();
	var subscribe = $("#subscribe").val();
	var jwid = $("#jwid").val();
	var url =basePath+"/commonluckymoney/recieveState.do";
	$.ajax({
		url : url,
		type : 'post',
		dataType : 'json',
		data : {
			actId : actId,
			openid : openid,
			jwid : jwid
		},
		success : function(data, status) {
			if (data.success) {
				popuphide('binner1');
				popup('binner2');
				if(data.attributes.luky){
					if(data.attributes.recieve){
						popup('ylj');
					}else{						
						popup('yzj');
					}
					$('span[name="record"]').html(data.obj.awardsName);
				}else{
					popup('wzj');
				}
			}else{
				$("#extractAwards").attr("href","javascript:extractAwards();");
			} 
		}
	});
	
}
function extractAwards() {
    //update-begin--Author:zhaofei  Date:20190827 for：经典模板在拆红包前判断是否关注公众号
	var subscribe = $("#subscribe").val();
	console.log(subscribe)
	if (subscribe == 0) {
		popup("act_focus");
	}else{
     //update-end--Author:zhaofei  Date:20190827 for：经典模板在拆红包前判断是否关注公众号
		$("#extractAwards").removeAttr("href");
		var actId = $("#actId").val();
		var openid = $("#openid").val();
		var subscribe = $("#subscribe").val();
		var jwid = $("#jwid").val();
		var url = basePath+"/commonluckymoney/extractAwards.do";
		$.ajax({
			url : url,
			type : 'post',
			dataType : 'json',
			data : {
				actId : actId,
				openid : openid,
				jwid : jwid
			},
			success : function(data, status) {
				$("#extractAwards").attr("href","javascript:extractAwards();");
				if (data.success) {
					popuphide('binner1');
					popup('binner2');
					if(data.attributes.luky){
						popup('yzj');
						$('span[name="record"]').html(data.obj.awardsName);
					}else{
						popup('wzj');
					}
				} else {
					$("#tip_msg_content").html(data.msg);
					popup('tip_msg');
				}
			}
		});
	}
}

function recieve(){
	var subscribe = $("#subscribe").val();
	if (subscribe == 0) {
		popup("act_focus");
		return;
	}
	popup('isNotBind');
}
function recieveAwards() {
	var mobile=$("#mobile").val();
	var reg=/^1((3\d)|(4[579])|(5[012356789])|(7[01235678])|(8\d))\d{8}$/;
	if(!reg.test(mobile)){
		alert("请输入正确的手机号!");
		return;
	}
	popuphide('isNotBind');
	var actId = $("#actId").val();
	var openid = $("#openid").val();
	var jwid = $("#jwid").val();
	var url = basePath+"/commonluckymoney/recieveAwards.do";
	$.ajax({
		url : url,
		type : 'post',
		dataType : 'json',
		data : {
			actId : actId,
			openid : openid,
			jwid : jwid,
			mobile:mobile
		},
		success : function(data, status) {
			if (data.success) {
				popuphide('yzj');
				popup('ylj');
				$('span[name="record"]').html(data.obj.awardsName);
			} else {
				$("#tip_msg_content").html(data.msg);
				popup('tip_msg');
			}
		}
	});
}  
function popup(id) {
	$("#" + id).show();
}

function popuphide(id) {
	$("#" + id).hide();
}
